<?php
$q=$_GET["q"];
$array= explode(",",$q);
$q=$array[0];
$cou_arr=count($array);
$NIC_Number=$array[$cou_arr-1];
$Access_Type=$array[$cou_arr-2];
$hint="";
include_once 'Login/databaseconnection.php';
if($q!="Select One")
{
if($q=="Schools with Labs")
{
$School_Ids="";
if($Access_Type=="Administrator")
	{
$result=mysql_query("SELECT DISTINCT(School_Id) FROM lab");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
	$get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	}
	}
	if($result)
{
while($row=mysql_fetch_array($result))
{
if(empty($School_Ids))
{
$School_Ids=$row['School_Id'];
}
else
{
$School_Ids=$School_Ids.",".$row['School_Id'];
}
}
$S_Ids=explode(",",$School_Ids);
if(count($S_Ids)!=0)
{
$hint='<div style="overflow-y:scroll;"><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">School Id</th><th width="230">Census Number</th><th width="230">Name</th><th width="230">Address</th><th width="230">Number of Labs</th></tr>';
for($i=0;$i<count($S_Ids);$i++)
{
$resultsc=mysql_query("SELECT * FROM school WHERE School_Id='$S_Ids[$i]'");
if($rowsc=mysql_fetch_array($resultsc))
{
$Census_Number=$rowsc['Census_Number'];
$Name=$rowsc['Name'];
$Address=$rowsc['Address'];
$no_labs=mysql_query("SELECT COUNT(Lab_Id) As Tot_No FROM lab WHERE School_Id='".$S_Ids[$i]."' GROUP BY School_Id");
if($rownum=mysql_fetch_array($no_labs))
{
$No_Labs=$rownum['Tot_No'];
$hint=$hint.'<tr align="center" bgcolor="#6AB5FF"><th width="80">'.$S_Ids[$i].'</th><th width="230">'.$Census_Number.'</th><th width="230">'.$Name.'</th><th width="230">'.$Address.'</th><th width="230">'.$No_Labs.'</th></tr>';
}
}
}
if($hint=='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">School Id</th><th width="230">Census Number</th><th width="230">Name</th><th width="230">Address</th><th width="230">Number of Labs</th></tr>')
{
$hint='<table border="0" class="tablefontv" width="540" align="left">';
$hint=$hint.'<img src="images/alert.jpg" width="12" height="12"/><font color="red">Sorry there are no results for you!</font>';
}
$hint=$hint.'</table></div>';
}
mysql_free_result($result);
}
}
if($q=="Schools without Labs")
{
$School_Ids="";
$w_o_labs="";
if($Access_Type=="Administrator")
{
$result=mysql_query("SELECT DISTINCT(School_Id) FROM programmes");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
	$get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	}
	}
	if($result)
{
while($row=mysql_fetch_array($result))
{
if(empty($School_Ids))
{
$School_Ids=$row['School_Id'];
}
else
{
$School_Ids=$School_Ids.",".$row['School_Id'];
}
}
$S_Ids=explode(",",$School_Ids);
if(count($S_Ids)!=0)
{
for($i=0;$i<count($S_Ids);$i++)
{
$resultl=mysql_query("SELECT * FROM lab WHERE School_Id='$S_Ids[$i]'");
if(mysql_num_rows($resultl)==0)
{
if(empty($w_o_labs))
{
$w_o_labs=$S_Ids[$i];
}
else
{
$w_o_labs=$w_o_labs.",".$S_Ids[$i];
}
}
}
$wi_o_labs=explode(",",$w_o_labs);
if(!empty($wi_o_labs))
{
$hint='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">School Id</th><th width="230">Census Number</th><th width="230">Name</th><th width="230">Address</th><th width="230">Number of Programmes</th></tr>';
for($j=0;$j<count($wi_o_labs);$j++)
{
$resultsc=mysql_query("SELECT * FROM school WHERE School_Id='$wi_o_labs[$j]'");
if($rowsc=mysql_fetch_array($resultsc))
{
$Census_Number=$rowsc['Census_Number'];
$Name=$rowsc['Name'];
$Address=$rowsc['Address'];
$no_pgs=mysql_query("SELECT COUNT(Programme_Id) As Tot_No FROM programmes WHERE School_Id='".$wi_o_labs[$j]."' GROUP BY School_Id");
if($rownum=mysql_fetch_array($no_pgs))
{
$No_Progs=$rownum['Tot_No'];
$hint=$hint.'<tr align="center" bgcolor="#6AB5FF"><th width="80">'.$wi_o_labs[$j].'</th><th width="230">'.$Census_Number.'</th><th width="230">'.$Name.'</th><th width="230">'.$Address.'</th><th width="230">'.$No_Progs.'</th></tr>';
}
}
}
if($hint=='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">School Id</th><th width="230">Census Number</th><th width="230">Name</th><th width="230">Address</th><th width="230">Number of Programmes</th></tr>')
{
$hint='<table border="0" class="tablefontv" width="540" align="left">';
$hint=$hint.'<img src="images/alert.jpg" width="12" height="12"/><font color="red">Sorry there are no results for you!</font>';
}
$hint=$hint.'</table></div>';
}
}
mysql_free_result($result);
}
}
if($q=="Resource Persons")
{
$result=mysql_query("SELECT * FROM resource_team");
$hint='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">NIC Number</th><th width="230">First Name</th><th width="230">Last Name</th><th width="230">Training Name</th></tr>';
if($result)
{
while($row=mysql_fetch_array($result))
{
$nic=$row['T_NIC_Number'];
$Tra_Id=$row['Training_Id'];
$get_tra=mysql_query("SELECT * FROM Training WHERE Training_Id='$Tra_Id'");
if($trarow=mysql_fetch_array($get_tra))
{
$Training_Name=$trarow['Training_Name'];
}
$resultd=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$nic'");
if($rowd=mysql_fetch_array($resultd))
{
$First_Name=$rowd['First_Name'];
$Last_Name=$rowd['Last_Name'];
$School_Id==$rowd['School_Id'];
if($Access_Type=="Administrator")
	{
$hint=$hint.'<tr align="center" bgcolor="#6AB5FF"><th width="80">'.$nic.'</th><th width="230">'.$First_Name.'</th><th width="230">'.$Last_Name.'</th><th width="230">'.$Training_Name.'</th></tr>';
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
	$get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	}
	if($Own_School_Id==$School_Id)
	{
$hint=$hint.'<tr align="center" bgcolor="#6AB5FF"><th width="80">'.$nic.'</th><th width="230">'.$First_Name.'</th><th width="230">'.$Last_Name.'</th><th width="230">'.$Training_Name.'</th></tr>';
}
}
}
}
if($hint=='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">NIC Number</th><th width="230">First Name</th><th width="230">Last Name</th></tr>')
{
$hint='<table border="0" class="tablefontv" width="540" align="left">';
$hint=$hint.'<img src="images/alert.jpg" width="12" height="12"/><font color="red">Sorry there are no results for you!</font>';
}
$hint=$hint.'</table></div>';
mysql_free_result($result);
}
}
if($q=="ICT Teachers")
{
if($Access_Type=="Administrator")
{
$resultit=mysql_query("SELECT * FROM teacher WHERE Appointed_Subject='ICT' OR Appointed_Subject='GIT'");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
	$get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$resultit=mysql_query("SELECT * FROM teacher WHERE Appointed_Subject='ICT' OR Appointed_Subject='GIT' AND School_Id='$Own_School_Id'");
	}
	}
$hint='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">NIC Number</th><th width="230">First Name</th><th width="230">Last Name</th></tr>';
if($resultit)
{
while($rowit=mysql_fetch_array($resultit))
{
$nicit=$rowit['T_NIC_Number'];
$First_Nameit=$rowit['First_Name'];
$Last_Nameit=$rowit['Last_Name'];
$hint=$hint.'<tr align="center" bgcolor="#6AB5FF"><th width="80">'.$nicit.'</th><th width="230">'.$First_Nameit.'</th><th width="230">'.$Last_Nameit.'</th></tr>';
}
if($hint=='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">NIC Number</th><th width="230">First Name</th><th width="230">Last Name</th></tr>')
{
$hint='<table border="0" class="tablefontv" width="540" align="left">';
$hint=$hint.'<img src="images/alert.jpg" width="12" height="12"/><font color="red">Sorry there are no results for you!</font>';
}
$hint=$hint.'</table></div>';
mysql_free_result($resultit);
}
}
if($q=="Graduate Teachers")
{
if($Access_Type=="Administrator")
{
$result=mysql_query("SELECT * FROM teacher");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
	$get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$result=mysql_query("SELECT * FROM teacher WHERE School_Id='$Own_School_Id'");
	}
	}
$hint='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">NIC Number</th><th width="230">First Name</th><th width="230">Last Name</th></tr>';
if($result)
{
while($row=mysql_fetch_array($result))
{
$nic=$row['T_NIC_Number'];
$Academic_Qualifications=$row['Academic_Qualifications'];
$ac_qua= explode(',',$Academic_Qualifications);
for($i=0;$i<count($ac_qua);$i++)
{
if(substr($ac_qua[$i],0,4)=="deg_")
{
$First_Name=$row['First_Name'];
$Last_Name=$row['Last_Name'];
$hint=$hint.'<tr align="center" bgcolor="#6AB5FF"><th width="80">'.$nic.'</th><th width="230">'.$First_Name.'</th><th width="230">'.$Last_Name.'</th></tr>';
}
}
}
if($hint=='<div style ="overflow-y:scroll; "><table border="0" class="tablefontv" width="540" align="left"><tr align="center" bgcolor="#999999"><th width="80">NIC Number</th><th width="230">First Name</th><th width="230">Last Name</th></tr>')
{
$hint='<table border="0" class="tablefontv" width="540" align="left">';
$hint=$hint.'<img src="images/alert.jpg" width="12" height="12"/><font color="red">Sorry there are no results for you!</font>';
}
$hint=$hint.'</table></div>';
mysql_free_result($result);
}
}
}
if($hint=="")
{
$response='<img src="images/alert.jpg" width="12" height="12"/><font color="red">Sorry there are no results for you!</font>';
}
else
{
$response=$hint;
}
echo $response;
?>